define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'offices/index' + location.search,
                    // add_url: 'offices/add',
                    edit_url: 'offices/edit',
                    // del_url: 'offices/del',
                    // multi_url: 'offices/multi',
                    import_url: 'offices/import',
                    table: 'offices',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'user.username', title: __('员工账号'), operate: 'LIKE'},
                        {
                            field: 'type',
                            title: __('Type'),
                            searchList: {
                                "1": __('补卡'),
                                "2": __('请假'),
                                "3": __('出差'),
                                "4": __('外出'),
                                "5": __('加班'),
                                "6": __('换班'),
                            },
                            formatter: Table.api.formatter.status
                        },
                        {
                            field: 'type1',
                            title: __('Type1'),
                            searchList: {
                                "1": __('事假'),
                                "2": __('病假'),
                                "3": __('调休'),
                                "4": __('其它'),
                            },
                            formatter: Table.api.formatter.status
                        },
                        {
                            field: 'start_time',
                            title: __('Start_time'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'end_time',
                            title: __('End_time'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'to_address',
                            title: __('To_address'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'image',
                            title: __('Image'),
                            operate: false,
                            events: Table.api.events.image,
                            formatter: Table.api.formatter.image
                        },
                        {field: 'audit_id', title: __('Audit_id')},
                        {field: 'audit_remark', title: __('Audit_remark'), operate: 'LIKE'},
                        {field: 'audit_time', title: __('Audit_time'), operate: 'LIKE'},
                        {
                            field: 'status',
                            title: __('Status'),
                            searchList: {
                                "1": __('待审核'),
                                "3": __('领导拒批'),
                                "5": __('领导同意'),
                                "7": __('后台拒批'),
                                "10": __('后台同意')
                            },
                            formatter: Table.api.formatter.status
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
